<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="90px"
    >
      <el-form-item label="执勤点名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入执勤点名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          plain
        >搜索
        </el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置
        </el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:stagnation_point:add']"
        >新增执勤点
        </el-button
        >
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          plain-->
      <!--          icon="el-icon-download"-->
      <!--          size="mini"-->
      <!--          @click="handleExport"-->
      <!--          v-hasPermi="['system:stagnation_point:export']"-->
      <!--        >导出-->
      <!--        </el-button-->
      <!--        >-->
      <!--      </el-col>-->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table
      v-loading="loading"
      :data="postList"
    >
      <el-table-column label="执勤点名称" align="center" prop="name"/>
      <el-table-column
        label="所在地区"
        align="center"
        prop="inAddress"
      />
      <el-table-column
        prop="type"
        align="center"
        label="执勤点类型"
      >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_stagnation_type"
            :value="scope.row.type"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="执勤点人数"
        align="center"
        prop="number"
      />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="120"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['system:stagnation_point:query']"
          >详情
          </el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:stagnation_point:edit']"
          >编辑
          </el-button>
          <!--          <el-button-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            @click="handleViewTeam(scope.row)"-->
          <!--            v-hasPermi="['system:team:list']"-->
          <!--          >查看团队-->
          <!--          </el-button-->
          <!--          >-->
          <!--          <el-button-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            @click="paibanFn(scope.row)"-->
          <!--            v-hasPermi="['system:team:list']"-->
          <!--          >排班-->
          <!--          </el-button-->
          <!--          >-->
          <!--          <el-button-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            @click="banciFn(scope.row)"-->
          <!--            v-hasPermi="['system:team:list']"-->
          <!--          >班次管理-->
          <!--          </el-button-->
          <!--          >-->
          <!--          <el-button-->
          <!--            v-if="scope.row.parentId != 0"-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            @click="handleDelete(scope.row)"-->
          <!--            v-hasPermi="['system:stagnation_point:remove']"-->
          <!--          >删除-->
          <!--          </el-button-->
          <!--          >-->
          <!--          <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)"-->
          <!--                       v-hasPermi="['system:role:edit']">-->
          <!--            <el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>-->
          <!--            <el-dropdown-menu slot="dropdown">-->
          <!--              <el-dropdown-item command="handleDataScope" icon="el-icon-date"-->
          <!--                                v-hasPermi="['system:role:edit']">班次管理-->
          <!--              </el-dropdown-item>-->
          <!--              <el-dropdown-item command="handleDataEdit" icon="el-icon-edit-outline"-->
          <!--                                v-hasPermi="['system:role:edit']">编辑-->
          <!--              </el-dropdown-item>-->
          <!--              <el-dropdown-item command="handleAuthDetel" icon="el-icon-delete"-->
          <!--                                v-hasPermi="['system:role:edit']">删除-->
          <!--              </el-dropdown-item>-->
          <!--            </el-dropdown-menu>-->
          <!--          </el-dropdown>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!--    执勤点人员-->
    <!--    <zhudianTeam :visible.sync="teamVisible" :param="param"></zhudianTeam>-->
    <!--    执勤点编辑-->
    <zhudianAdd :visible.sync="zhudianVisible" @getList="getList" :paramId="paramId"></zhudianAdd>
    <!--    班次设置-->
    <!--    <classesList :visible.sync="listVisible" :param="param"></classesList>-->
    <!--    排班-->
    <!--    <scheduling :visible.sync="schedulingVisible" :param="param"></scheduling>-->
  </div>
</template>

<script>
import {
  listStagnationPoint,
  getStagnationPoint,
  delStagnationPoint,
  addStagnationPoint,
  updateStagnationPoint
} from "@/api/system/stagnation_point";
import zhudianTeam from "@/components/zhudian-team/index"
import zhudianAdd from "@/components/zhudian/add"
import classesList from "@/components/classes/list";
import scheduling from "@/components/classes/scheduling";

export default {
  name: "StagnationPoint",
  dicts: ['sys_stagnation_type'],
  components: {zhudianTeam, zhudianAdd, classesList, scheduling},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      postList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        postCode: undefined,
        postName: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      paramId: 0,
      teamVisible: false,
      param: null,
      zhudianVisible: false,
      listVisible: false,
      schedulingVisible: false
    };
  },
  watch: {},
  created() {
    this.getList()
  },
  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      listStagnationPoint(this.queryParams).then(response => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.postId)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleDataScope":
          // 班次管理
          this.banciFn(row);
          break;
        case "handleDataEdit":
          // 编辑
          this.handleUpdate(row);
          break;
        case "handleAuthDetel":
          // 删除
          this.handleDelete(row);
          break;
        default:
          break;
      }
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.paramId = 0
      this.zhudianVisible = true
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.paramId = row.id
      this.zhudianVisible = true
    },
    paibanFn(row) {
      this.param = JSON.parse(JSON.stringify(row))
      this.schedulingVisible = true
    },
    banciFn(row) {
      this.param = JSON.parse(JSON.stringify(row))
      this.listVisible = true
    },
    handleViewTeam(row) {
      this.param = JSON.parse(JSON.stringify(row))
      this.teamVisible = true
    },
    handleView(row) {
      this.$router.push(`/stagnation_point/detail/index/${row.id}`)
    },
    // 用户状态修改
    handleStatusChange(row) {
      let text = row.status === "0" ? "启用" : "停用";
      this.$modal.confirm('确认要"' + text + '""' + row.name + '"执勤点吗？').then(function () {
        return updateStagnationPoint({id: row.id, status: row.status});
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function () {
        row.status = row.status === "0" ? "1" : "0";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateStagnationPoint(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStagnationPoint(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认删除执勤点为"' + row.name + '"的数据项？').then(function () {
        return delStagnationPoint(row.id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/stagnation_point/export', {
        ...this.queryParams
      }, `post_${new Date().getTime()}.xlsx`)
    },
    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.getList();
    }
  }
};
</script>
<style lang="scss" scoped>
.points-map {
  height: 400px;
}

.points-map__tip {
  color: #010101;
  font-size: 14px;
  font-weight: 700;
  line-height: 20px;
}

.point-radius {
  margin-bottom: 20px;
  padding: 0 20px;

  .point-radius__len {
    margin-top: 10px;
    display: flex;
    display: -webkit-flex;
    justify-content: space-between;
    color: #010101;
    font-size: 14px;
    font-weight: 400;
    line-height: 20px;
  }
}

.mapBox {
  margin-bottom: 20px;
  padding: 0 20px;
}
</style>
